<template>
  <div id="table_container">
    <el-card style="margin-bottom: 5px; text-align: left">
      <el-input v-model="keyWord" placeholder="输入搜索内容" style="width: 200px;" @keyup.enter.native="handleFilter"></el-input>
      <el-button type="primary" icon="el-icon-search" @click="handleFilter" style="margin-left: 10px;">
        查询
      </el-button>
    </el-card>
    <el-card>
      <el-table
          :data="tableData"
          v-loading="loading"
          row-key="id"
          border>
        <el-table-column
            type="selection"
            align="center"
            width="48">
        </el-table-column>
        <el-table-column
            type="index"
            label="序号"
            align="center"
            width="50">
        </el-table-column>
        <el-table-column
            prop="username"
            label="登录用户名">
        </el-table-column>
        <el-table-column
            prop="ip"
            label="登录ip">
        </el-table-column>
        <el-table-column
            prop="continent"
            label="大州"
            align="center">
        </el-table-column>
        <el-table-column
            prop="country"
            label="国家"
            align="center">
        </el-table-column>
        <el-table-column
            prop="province"
            label="省份"
            align="center">
        </el-table-column>
        <el-table-column
            prop="city"
            label="城市"
            align="center">
        </el-table-column>
        <el-table-column
            prop="district"
            label="县区"
            align="center">
        </el-table-column>

        <el-table-column
            prop="area_code"
            label="区域代码"
            align="center">
        </el-table-column>
        <el-table-column
            prop="country_english"
            label="英文名称"
            align="center">
        </el-table-column>
        <el-table-column
            prop="country_code"
            label="简称"
            align="center">
        </el-table-column>
        <el-table-column
            prop="os"
            label="操作系统"
            align="center">
        </el-table-column>
        <el-table-column
            prop="browser"
            label="浏览器"
            align="center">
        </el-table-column>
        <el-table-column
            label="登录时间"
            align="center"
            width="120">
          <template slot-scope="scope">
            <i class="el-icon-time"></i>
            <span style="margin-left: 10px">{{ scope.row.create_time }}</span>
          </template>
        </el-table-column>
        <!--      <el-table-column-->
        <!--          fixed="right"-->
        <!--          width="170"-->
        <!--          align="center"-->
        <!--          label="操作">-->
        <!--        <template slot-scope="scope">-->
        <!--          <el-button @click="handleClick(scope.row)" icon="el-icon-search" circle></el-button>-->
        <!--          <el-button @click="handleClick(scope.row)" type="primary" icon="el-icon-edit" circle></el-button>-->
        <!--          <el-button @click="handleClick(scope.row)" type="danger" icon="el-icon-delete" circle></el-button>-->
        <!--        </template>-->
        <!--      </el-table-column>-->

      </el-table>
      <pagination
          v-show="pageTotal>0"
          :total="pageTotal"
          :page.sync="page"
          :pageSize.sync="pageSize"
          @pagination="getDataList"/>
    </el-card>
  </div>
</template>

<script>
import {getLoginLog} from "@/api";
import pagination from "@/components/Pagenation";

export default {
  name: "index",
  components: {
    pagination
  },
  data() {
    return {
      tableData: [],
      loading: true,
      keyWord: undefined,

      // 分页器相关
      page: 1,
      pageTotal: 0,
      pageSize: 10,
    }
  },
  mounted() {
    this.getDataList()
  },
  methods: {
    getDataList(params = {}) {
      this.loading = true

      params['page'] = this.page
      params['pageSize'] = this.pageSize
      params['keyWord'] = this.keyWord
      getLoginLog(params).then(res => {
        this.tableData = res.data.results;
        this.pageTotal = res.data.count;
        setTimeout(() => {
          this.loading = false
        }, 1.5 * 500)
      })
    },
    handleFilter() {
      this.getDataList()
    },
  }
}
</script>

<style scoped>

</style>